//
// Created by 刘禹晨 on 16/5/25.
// Copyright (c) 2016 刘禹晨. All rights reserved.
//

#import "TabViewController.h"
#import "ViewController.h"
#import "NodeViewController.h"
#import "MyTabbar.h"
#import "MenuView.h"
#import "MMDrawerController/UIViewController+MMDrawerController.h"
#import "MainViewController.h"
#import "SecondMainViewController.h"
#import "SettingViewController.h"

@interface TabViewController () <UITabBarControllerDelegate>
{
    NSArray *controllers;
    ViewController *mainView;
    NodeViewController *nodeView;
    MainViewController *navView;
    SecondMainViewController *secnavView;
    //SettingViewController *settingView;
    
}
@end

@implementation TabViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    mainView = [[ViewController alloc]init];
    nodeView = [[NodeViewController alloc]init];
    //settingView = [[SettingViewController alloc]init];

    navView = [[MainViewController alloc] initWithRootViewController:mainView];
    secnavView = [[SecondMainViewController alloc] initWithRootViewController:nodeView];

    [self addChildController:navView title:@"列表" image:@"list_none"];
    [self addChildController:secnavView title:@"节点" image:@"nodeweb"];


    MyTabbar *tabBar = [[MyTabbar alloc] init];
    //tabBar.tabBarDelegate = self;
    tabBar.tintColor = [[UIColor new] initWithRed:255.0f/255.0f green:73.0f/255.0f blue:64.0f/255.0f alpha:1.0f];
    [self setValue:tabBar forKeyPath:@"tabBar"];
    self.delegate = self;
    self.navigationItem.title = @"节点列表";
    self.selectIndex = 0;
    
}

- (void)viewDidAppear:(BOOL)animated {

    //NSLog(@"viewDidAppera");
}
- (void)viewWillAppear:(BOOL)animated {
    //    if(self.selectedIndex == 3)
    //    {
    //        [_meViewController refreshView];
    //    }
    //NSLog(@"viewWillAppera , %d",self.selectedIndex);
}



/**
 * 添加子控制器到UITabBarController中
 */
- (void)addChildController:(UIViewController *)childViewController title:(NSString *)title image:(NSString *)image
{
    // 设置子控制器，tabbar和navigationBar上的title
    childViewController.title = title;
    // 设置tabBarItem上默认的指示图片和选中时的图片
    childViewController.tabBarItem.image = [UIImage imageNamed:image];
    childViewController.tabBarItem.selectedImage = [[UIImage imageNamed:[image stringByAppendingString:@"_red"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 设置tabBarItem上文字的样式（这里是设置文字在不同状态下的颜色值）
    [childViewController.tabBarItem setTitleTextAttributes:
            @{NSForegroundColorAttributeName: [[UIColor new] initWithRed:117.0f/255.0f green:117.0f/255.0f blue:117.0f/255.0f alpha:1.0f]} forState:UIControlStateNormal];
    [childViewController.tabBarItem setTitleTextAttributes:
            @{NSForegroundColorAttributeName: [[UIColor new] initWithRed:255.0f/255.0f green:73.0f/255.0f blue:64.0f/255.0f alpha:1.0f]} forState:UIControlStateSelected];
    //UINavigationController *NA = [[UINavigationController alloc]initWithRootViewController:childViewController];
    [self addChildViewController:childViewController];

}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    self.selectIndex = tabBarController.selectedIndex;
    //NSLog(@"Select Index is : %lu", (unsigned long)tabBarController.selectedIndex);
}



@end